package org.groupg.filetodb.model.database;



import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;

import java.io.Serializable;

/**
 * 表示索引/统计信息元数据
 */
public class IndexInfo implements Serializable {
    /** 表目录 */
    private String tableCat;
    /** 表模式 */
    private String tableSchem;
    /** 表名 */
    private String tableName;
    /** 是否允许重复值 */
    private boolean nonUnique;
    /** 索引限定符 */
    private String indexQualifier;
    /** 索引名 */
    private String indexName;
    /** 索引类型 (DatabaseMetaData.tableIndexXXX) */
    private short type;
    /** 索引中的列序列号 */
    private short ordinalPosition;
    /** 列名 */
    private String columnName;
    /** 排序方式 "A" (ASC) 或 "D" (DESC) */
    private String ascOrDesc;
    /** 基数（唯一值数量） */
    private long cardinality;
    /** 页数 */
    private long pages;
    /** 过滤条件 */
    private String filterCondition;

    @Override
    public String toString() {
        return MoreObjects.toStringHelper(this)
                .add("tableCat", tableCat)
                .add("tableSchem", tableSchem)
                .add("tableName", tableName)
                .add("nonUnique", nonUnique)
                .add("indexQualifier", indexQualifier)
                .add("indexName", indexName)
                .add("type", type)
                .add("ordinalPosition", ordinalPosition)
                .add("columnName", columnName)
                .add("ascOrDesc", ascOrDesc)
                .add("cardinality", cardinality)
                .add("pages", pages)
                .add("filterCondition", filterCondition)
                .toString();
    }

    @Override
    public boolean equals(Object o) {
        if (o == null || getClass() != o.getClass()) return false;
        IndexInfo indexInfo = (IndexInfo) o;
        return isNonUnique() == indexInfo.isNonUnique() && getType() == indexInfo.getType() && getOrdinalPosition() == indexInfo.getOrdinalPosition() && getCardinality() == indexInfo.getCardinality() && getPages() == indexInfo.getPages() && Objects.equal(getTableCat(), indexInfo.getTableCat()) && Objects.equal(getTableSchem(), indexInfo.getTableSchem()) && Objects.equal(getTableName(), indexInfo.getTableName()) && Objects.equal(getIndexQualifier(), indexInfo.getIndexQualifier()) && Objects.equal(getIndexName(), indexInfo.getIndexName()) && Objects.equal(getColumnName(), indexInfo.getColumnName()) && Objects.equal(getAscOrDesc(), indexInfo.getAscOrDesc()) && Objects.equal(getFilterCondition(), indexInfo.getFilterCondition());
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(getTableCat(), getTableSchem(), getTableName(), isNonUnique(), getIndexQualifier(), getIndexName(), getType(), getOrdinalPosition(), getColumnName(), getAscOrDesc(), getCardinality(), getPages(), getFilterCondition());
    }

    public String getTableCat() {
        return tableCat;
    }

    public void setTableCat(String tableCat) {
        this.tableCat = tableCat;
    }

    public String getTableSchem() {
        return tableSchem;
    }

    public void setTableSchem(String tableSchem) {
        this.tableSchem = tableSchem;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public boolean isNonUnique() {
        return nonUnique;
    }

    public void setNonUnique(boolean nonUnique) {
        this.nonUnique = nonUnique;
    }

    public String getIndexQualifier() {
        return indexQualifier;
    }

    public void setIndexQualifier(String indexQualifier) {
        this.indexQualifier = indexQualifier;
    }

    public String getIndexName() {
        return indexName;
    }

    public void setIndexName(String indexName) {
        this.indexName = indexName;
    }

    public short getType() {
        return type;
    }

    public void setType(short type) {
        this.type = type;
    }

    public short getOrdinalPosition() {
        return ordinalPosition;
    }

    public void setOrdinalPosition(short ordinalPosition) {
        this.ordinalPosition = ordinalPosition;
    }

    public String getColumnName() {
        return columnName;
    }

    public void setColumnName(String columnName) {
        this.columnName = columnName;
    }

    public String getAscOrDesc() {
        return ascOrDesc;
    }

    public void setAscOrDesc(String ascOrDesc) {
        this.ascOrDesc = ascOrDesc;
    }

    public long getCardinality() {
        return cardinality;
    }

    public void setCardinality(long cardinality) {
        this.cardinality = cardinality;
    }

    public long getPages() {
        return pages;
    }

    public void setPages(long pages) {
        this.pages = pages;
    }

    public String getFilterCondition() {
        return filterCondition;
    }

    public void setFilterCondition(String filterCondition) {
        this.filterCondition = filterCondition;
    }
}